/*
 * 
 *
 *
 */
package com.hboxs.asl.dao.impl;

import com.hboxs.asl.dao.CommonContentDao;
import com.hboxs.asl.entity.CommonContent;
import org.springframework.stereotype.Repository;

import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;

/**
 * Dao - 通用内容
 */
@Repository("commonContentDaoImpl")
public class CommonContentDaoImpl extends BaseDaoImpl<CommonContent, Long> implements CommonContentDao {

    @Override
    public CommonContent getUniqueness() {
        String jpql = "select commonContent from CommonContent commonContent ";
        CommonContent commonContent = null;
        try {
            commonContent = entityManager.createQuery(jpql, CommonContent.class).setFlushMode(FlushModeType.COMMIT).setMaxResults(1).getSingleResult();

        } catch (NoResultException e) {
            commonContent = new CommonContent();
            this.persist(commonContent);
        }
        return commonContent;
    }
}
